home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3117 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ syntax
  5. Date: Mon, 22 Jan 1996 12:34:20 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <3103763C.15FB7483@intellektik.informatik.th-darmstadt.de>
  8. References: <3102EDDA.45A6@tribeca.ios.com>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. John Leonard wrote:
  16. > In the book Borland C++ 4.5 Object-Oriented Programming by Ted Faison, Sam's Publishing, page
  17. > 603, there is an example using the Borland template class library. First, the idea is to instantiate
  18. > a class of type TListImp(from a template) and then instantiate an object of that type. And then to
  19. > instantiate a class of type TListIteratorImp from a template, and then to instantiate an object of
  20. > that type. The TListIterator object will be used to move through the TListImp object. The details
  21. > about these class templates are not what my question is about, but rather the syntax of one of the
  22. > lines in the program is:
  23. >      TListIteratorImp<string>     next(a);  // where a is an object of type TListImp<string>
  24. >      ...
  25. >      while(next)     // ??
  26. >      ...
  27. >      What does this line mean? How does it work?
  28.  
  29. Take a look at 'conversion operators'.
  30. The iterator class most likely provides an operator like
  31.  
  32.              operator bool () const { ... }
  33.  
  34. or the appropriate {int,void*}-conversion. In that case 'while (next)'
  35. reads as 'while (next.operator bool())'.  The operator returns true
  36. iff the actual position of the iterator points to a valid element, so
  37. the loop is executed until the actual position points to an invalid
  38. element.
  39.  
  40.     Enno
  41.